php chech if string contains

52

php chech if string contains -

$a = 'How are you?';

if (strpos($a, 'are') !== false) {
    echo 'true';
}

check if string contains character php -

// this method is new with PHP 8 and above
$haystack = "Damn, I wonder if this string contains a comma.";
if (str_contains($haystack, ",")) {
	echo "There is a comma!!";
}

php check if string contains -

// returns true if $needle is a substring of $haystack
function contains($haystack, $needle){
    return strpos($haystack, $needle) !== false;
}

Comments

Submit
0 Comments